<?php

namespace App\Admin\Actions\Coupon;

use App\Models\CouponModel;
use Encore\Admin\Actions\RowAction;
use Encore\Admin\Actions\Response;

class CouponStopAction extends RowAction
{
    public $name = '停止发送';

    /**
     * handle
     * @param CouponModel $model
     * @return Response
     */
    public function handle(CouponModel $model): Response
    {
        $model->status = 2;
        $model->send_end_at = now();
        $model->save();
        return $this->response()->success('操作成功')->refresh();
    }

    public function dialog(): void
    {
        $this->confirm('确定发送吗?');
    }
}
